package com.lazy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lazy.dao.BicycleDao;
import com.lazy.entity.Bicycle;
import com.lazy.service.BicycleService;
import com.lazy.utils.RespBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("bicycleService")
public class BicycleServiceImpl implements BicycleService {
    @Resource
    private BicycleDao bicycleDao;

    @Override
    public RespBean addBicycle(Bicycle bicycle) {
        if (bicycleDao.addBicycle(bicycle)) {
            return RespBean.success("添加单车成功");
        }
        return RespBean.error("添加单车失败");
    }

    @Override
    public RespBean PageBicycle(Integer pageCurrent, Integer pageSize) {
        PageHelper.startPage(pageCurrent, pageSize);
        List<Bicycle> bicycle = bicycleDao.PageBicycle();
        if (bicycle != null) {
            PageInfo<Bicycle> result = new PageInfo<>(bicycle);
            return RespBean.success("获取单车信息成功", result);
        }
        return RespBean.error("获取单车信息成功");
    }

    @Override
    public RespBean deleteBicycle(Integer id) {
        if (bicycleDao.deleteBicycle(id)) {
            return RespBean.success("删除单车信息成功");
        }
        return RespBean.success("删除单车信息失败");
    }

    @Override
    public RespBean upBicycle(Bicycle bicycle) {
        if (bicycleDao.upBicycle(bicycle)) {
            return RespBean.success("修改单车信息成功");
        }
        return RespBean.success("修改单车信息失败");
    }
}
